/******************************************************************************
COPYRIGHT (C) 2013 by IT-Designers GmbH

File:		BSpline.h
Created:	13.03.2013
Modified:	13.03.2013
Author:		Max Pejs
******************************************************************************/

#ifndef BSPLINE_H
#define BSPLINE_H

#include "Line2D.h"

#include <iostream>

using namespace std;

class SplinePoint
{
public:
	SplinePoint();
	SplinePoint(double x, double y, double z);
	
	const SplinePoint operator*(double value);
	const SplinePoint operator+(const SplinePoint & other);
	const void operator+=(const SplinePoint & other);
	double CalcDistTo(SplinePoint & other);

	double x;
	double y;
	double z;
};

class BSpline
{
private:
	/**
	*	Array with base points coordinates
	*/
	SplinePoint * ControlPointVec;

	/**
	*	Node vector
	*/
	int * t;

	/**
	*	Order + 1
	*/
	int k;

	/**
	*	Base point counter
	*/
	int n;

	/**
	*	Computes the vector with node points
	*/
	void CompNodeVec();

	/*
	*	Recursive Method for summand computation
	*/
	double BSpline::N(int i, int k, double v);

public:
	/**
	*	Ctor.
	*/
	BSpline(int order, SplinePoint * ctrPoints, int pointCnt);
	~BSpline();

	/**
	 *	Calculates single point on the B-Spline curve given by parameter
	 */
	SplinePoint CalcPoint(double Value /* 0.0 ... 1.0 */);

	/**
	*	Calculates a couple of points on the B-Spline curve
	*/
	SplinePoint * CalcPoints(int counter, double start = 0.0, double end = 1.0 );

	double FindCtrPointWithMaxError(int & index);

};

#endif	// BSPLINE_H